

import 'dart:async';

import 'package:flutter/widgets.dart';

class TimerModel extends ChangeNotifier{


  Timer? _timer;

  int _count = 0;//当前计数
  int get count => 10 - _count;

  _setCount(){
    _count ++;
    notifyListeners();
  }

  startTimer(){
    _count = 0;
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      _setCount();
      if(_count == 10){
        _timer?.cancel();
      }
    });

  }

  @override
  void dispose() {
    // TODO: implement dispose
    _timer?.cancel();
    super.dispose();
  }

}